/*
 * @Author: Clark
 * @Email: haixuanwoTxh@gmail.com
 * @Date: 2023-01-09 17:37:41
 * @LastEditors: Clark
 * @LastEditTime: 2023-01-09 17:44:36
 * @Description: file content
 */

#include "apue.h"
#include <pwd.h>

static void my_alarm(int signo)
{
    struct  passwd *rootptr = NULL;
    printf("in signal handler\n");

    rootptr = getpwnam("root");
    if (NULL == rootptr)
    {
        err_sys("getpwnam(root) error");
    }

    alarm(1);
}

int main(void)
{
    struct  passwd *ptr;

    signal(SIGALRM, my_alarm);
    alarm(1);

    for(;;)
    {
        if ((ptr = getpwnam("txh")) == NULL)
        {
            err_sys("getpwnam error");
        }

        if (strcmp(ptr->pw_name, "txh") != 0)
        {
            printf("return value corrupted!, pw_name = %s\n", ptr->pw_name);
        }
    }
}
